package com.woniuxy.qimengcommons.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.woniuxy.qimengcommons.enums.RespStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Tolerate;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReturnMsg<T> implements Serializable {

    private Integer code;
    private String message;
    /**
     * 令牌/凭证
     */
    private String token;

    //@JsonIgnore 将如下属性，取消序列化
    @JsonIgnore
    private RespStatus status;
    /**
     * 返回的数据
     */
    private T data;

    /**
     * 在@Builder 定义的JavaBean中，可以使用
     * @Tolerate 自定义构造器
     * @param status
     */
    @Tolerate
    public ReturnMsg(RespStatus status){
        this.code = status.getCode();
        this.message = status.getMessage();
    }

    public void setStatus(RespStatus status) {
        this.code = status.getCode();
        this.message = status.getMessage();
    }
}
